package com.example.design.deprecated.state;

import com.example.design.deprecated.DeprecatedConstants;
import com.example.design.deprecated.observe.DeprecatedAbstractObserver;

import java.util.List;
import java.util.Vector;

//状态模式的抽象状态类和观察者模式的抽象观察者类
public abstract class DeprecatedAbstractOrderState {

    //关联抽象观察者。以List进行关联，因为要支持观察者的添加和移除
    protected final List<DeprecatedAbstractObserver> observerList = DeprecatedConstants.OBSERVER_LIST;



    //订单状态，待支付，待发货，待收货，订单完成
    protected final String ORDER_WAIT_PAY = "ORDER_WAIT_PAY";
    protected final String ORDER_WAIT_SEND = "ORDER_WAIT_SEND";
    protected final String ORDER_WAIT_RECEIVE = "ORDER_WAIT_RECEIVE";
    protected final String ORDER_FINISH = "ORDER_FINISH";

    protected DeprecatedOrder createOrder(String orderId,String productId,DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    protected DeprecatedOrder payOrder(String orderId,DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    protected DeprecatedOrder sendOrder(String orderId,DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    protected DeprecatedOrder receiveOrder(String orderId,DeprecatedOrderContext context) {
        throw new UnsupportedOperationException();
    }

    //添加观察者
    public void addObserver(DeprecatedAbstractObserver observer) {
        observerList.add(observer);
    }

    //移除观察者
    public void removeObserver(DeprecatedAbstractObserver observer) {
        observerList.remove(observer);
    }

    //通知观察者进行相关操作
    public void notifyObserver(String orderId,String orderState) {
        for (DeprecatedAbstractObserver observer : observerList) {
            observer.orderStateHandle(orderId,orderState);
        }
    }


}
